package cn.lyj.study.controller;

import cn.lyj.study.pojo.Business;
import cn.lyj.study.service.BusinessService;
import cn.lyj.study.util.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@CrossOrigin("*")
@RequestMapping("/business")
public class OPBusinessController {
    //  自动注入
    @Autowired
    BusinessService businessService ;
    @ResponseBody
    @CrossOrigin
    @RequestMapping("/list")
    public PageInfo<Business> getBusiness(int currentPage, int pageSize){
       return businessService.getBusiness(currentPage, pageSize);
    }
    @ResponseBody
    @CrossOrigin
    @RequestMapping("/add")
    public String addBusiness(Business business){
        boolean b = businessService.addBusiness(business);
        if(b){
            return "ok" ;
        }
        return "error" ;
    }
    @ResponseBody
    @CrossOrigin
    @RequestMapping("/update")
    public String updateBusiness(Business business){
        boolean b = businessService.updateBusiness(business);
        if(b){
            return "ok" ;
        }
        return "error" ;
    }
    @ResponseBody
    @CrossOrigin
    @RequestMapping("/delect")
    public String delectBusiness(int businessId){
        boolean b = businessService.delectBusiness(businessId);
        if(b){
            return "ok" ;
        }
        return "error" ;
    }
}
